﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace MySQL.Db
{
    public enum GollieDb
    {
        Gollie,
        GollieMail,
        GollieAd
    }

    public class DbUtils
    {
		//using a dictionary is way faster than getting the connectionsting from the ConfigurationManager with each call.
		private static Dictionary<GollieDb, string> connectionStrings = new Dictionary<GollieDb, string>(4);

		public static string GetConnectionString(GollieDb db)
		{
			string connectionString;
			if (connectionStrings.TryGetValue(db, out connectionString) == false)
			{
				connectionString = ConfigurationManager.ConnectionStrings[db == GollieDb.Gollie ? "Main" : db == GollieDb.GollieMail ? "Mail" : db == GollieDb.GollieAd ? "Ad" : "Main"].ConnectionString;
				connectionStrings[db] = connectionString;
			}

			return connectionString;
		}
    }
}
